//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.jic.member.sms;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import java.util.Map;

import com.jic.member.exception.AppRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

public class AliyunSmsUtils {
    private static Logger _log = LoggerFactory.getLogger(AliyunSmsUtils.class);

    public AliyunSmsUtils() {
    }

    public static AliSmsSendResponse send(AliyunSmsConfig smsConfig, AliyunSmsCustomConfig customConfig, Map<String, String> param) throws Throwable {
        if (StringUtils.isEmpty(customConfig.getPhone())) {
            throw new AppRuntimeException("9999", new Object[0]);
        } else {
            DefaultProfile profile = DefaultProfile.getProfile("default", smsConfig.getAccessKeyId(), smsConfig.getSecret());
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setMethod(MethodType.POST);
            request.setDomain("dysmsapi.aliyuncs.com");
            request.setVersion("2017-05-25");
            request.setAction("SendSms");
            request.putQueryParameter("PhoneNumbers", customConfig.getPhone());
            request.putQueryParameter("SignName", smsConfig.getSignName());
            request.putQueryParameter("TemplateCode", smsConfig.getTemplateCode());
            request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));

            try {
                CommonResponse commonResponse = client.getCommonResponse(request);
                JSONObject obj = JSONObject.parseObject(commonResponse.getData());
                AliSmsSendResponse aliSmsSendResponse = (AliSmsSendResponse)JSONObject.toJavaObject(obj, AliSmsSendResponse.class);
                return aliSmsSendResponse;
            } catch (Exception var9) {
                _log.error("Call Ali SMS Fail", var9);
                return null;
            }
        }
    }
}
